package atguigu.sql;

import org.apache.commons.lang.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Demo1 {
    public static void main(String[] args) {

        dzgsField("电子公司1");
        dzgsField("电子公司2");
    }

    private static void dzgsField(String strategy) {
        HashMap<String, String> map = new HashMap<>();
        if (strategy.equals("电子公司1")) {
            String[] fields = new String[]{"温度上限", "温度下限", "时间", "高温试验温度", "预热温度", "高温试验时间", "低温试验温度", "预冷温度", "低温试验时间", "试验周期", "除霜周期"};
            map = _createFieldsMap2(fields);
        } else if (strategy.equals("电子公司2")) {
            String[] fields = new String[]{"温度上限", "温度下限", "湿度上限", "湿度下限", "时间"};
            map = _createFieldsMap2(fields);
        }

        for (Map.Entry<String, String> entry : map.entrySet()) {
            String name = entry.getKey();
            String field = entry.getValue();
            String sql = "update scadaequipchecknodeinfo set sampleModel = '" + field + "' where strategy = '" + strategy + "' and checkNodeType = '" + name + "';";
            System.out.println(sql);
        }
    }

    private static void qichebupinField(String strategy) {
        HashMap<String, String> map = new HashMap<>();
        if (strategy.equals("汽车部品1")) { // 工业，合肥，汽车部品
            String[] fields = new String[]{"电流", "电压", "排气压力", "吸气压力", "排气温度", "吸气温度", "环境温度", "流量"};
            map = _createFieldsMap2(fields);
        } else if (strategy.equals("汽车部品2")) {
            String[] fields = new String[]{"电流", "电压", "排气压力", "吸气压力", "排气温度", "吸气温度", "环境温度", "壳体温度1", "壳体温度2", "壳体温度3", "壳体温度4"};
            map = _createFieldsMap2(fields);
        } else if (strategy.equals("汽车部品3")) {
            String[] fields = new String[]{"电流", "电压", "温度1", "温度2"};
            map = _createFieldsMap2(fields);
        } else if (strategy.equals("汽车部品4")) {
            String[] fields = new String[]{"电流1", "电流2", "电流3", "电压", "温度1", "温度2", "温度3", "温度4", "温度5", "温度6", "温度7", "温度8", "温度9", "温度10"};
            map = _createFieldsMap2(fields);
        }

        for (Map.Entry<String, String> entry : map.entrySet()) {
            String name = entry.getKey();
            String field = entry.getValue();
            String sql = "update scadaequipchecknodeinfo set sampleModel = '" + field + "' where strategy = '" + strategy + "' and checkNodeType = '" + name + "';";
            System.out.println(sql);
        }
    }


    private static HashMap<String, String> _createFieldsMap2(String[] fields) {
        HashMap<String, String> map = new HashMap<>();
        int length = fields.length;
        for (int i = 0; i < length; i++) {
            String field = fields[i];
            int index = i + 1;
            map.put(field, "varStr" + index);
        }
        return map;
    }

    private static HashMap<String, String> _createFieldsMap(String[] fields) {
        HashMap<String, String> map = new HashMap<>();
        int length = fields.length;
        for (int i = 0; i < length; i++) {
            String field = fields[i];
            map.put(field + "上限", "varStr" + (2 * i + 1));
            map.put(field + "下限", "varStr" + (2 * i + 2));
        }
        return map;
    }


}
